package bme.andraskindler.treenventory.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import bme.andraskindler.treenventory.R;
import bme.andraskindler.treenventory.provider.RestManager;
import bme.andraskindler.treenventory.provider.RestManager.NetInfo;

public class ConnectionFragment extends Fragment {

	private TextView mWifi, mMobile;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		final View root = inflater.inflate(R.layout.fragment_connection, container, false);

		mWifi = TextView.class.cast(root.findViewById(R.id.tv_connection_wifi));
		mMobile = TextView.class.cast(root.findViewById(R.id.tv_connection_mobile));

		updateStatus();
		
		return root;
	}

	public void updateStatus() {
		final NetInfo info = RestManager.isNetworkAvailable(getActivity());
		mWifi.setCompoundDrawablesWithIntrinsicBounds(info.wifi == true ? R.drawable.circle_green : R.drawable.circle_red, 0, 0, 0);
		mMobile.setCompoundDrawablesWithIntrinsicBounds(info.mobile == true ? R.drawable.circle_green : R.drawable.circle_red, 0, 0, 0);
	}

}
